```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>死锁检测指南 - 多线程编程的艺术</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            line-height: 1.6;
            color: #333;
        }
        .header-font {
            font-family: 'Noto Serif SC', serif;
        }
        .code-block {
            background: #f8f8f8;
            border-radius: 8px;
            overflow: hidden;
        }
        .code-header {
            background: #e0e0e0;
            padding: 8px 16px;
            font-weight: 500;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        pre {
            margin: 0;
            padding: 16px;
            overflow-x: auto;
        }
        .card:hover {
            transform: translateY(-4px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .hover-underline-animation {
            position: relative;
        }
        .hover-underline-animation:after {
            content: '';
            position: absolute;
            width: 100%;
            transform: scaleX(0);
            height: 2px;
            bottom: 0;
            left: 0;
            background-color: #4f46e5;
            transform-origin: bottom right;
            transition: transform 0.25s ease-out;
        }
        .hover-underline-animation:hover:after {
            transform: scaleX(1);
            transform-origin: bottom left;
        }
        .fade-in {
            animation: fadeIn 0.5s ease-in;
        }
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(10px); }
            to { opacity: 1; transform: translateY(0); }
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="relative bg-gradient-to-r from-indigo-900 to-purple-800 text-white py-20 md:py-32 px-4 md:px-8 overflow-hidden">
        <div class="max-w-6xl mx-auto relative z-10">
            <div class="flex flex-col md:flex-row items-center">
                <div class="md:w-1/2 mb-10 md:mb-0">
                    <h1 class="header-font text-4xl md:text-5xl font-bold leading-tight mb-6 fade-in">
                        多线程编程中的<br><span class="text-indigo-300">死锁检测艺术</span>
                    </h1>
                    <p class="text-xl text-indigo-200 mb-8 max-w-lg fade-in">
                        掌握死锁识别与解决方法，构建更健壮的高并发应用程序
                    </p>
                    <div class="flex flex-wrap gap-4 fade-in">
                        <a href="#methods" class="bg-white text-indigo-900 hover:bg-indigo-100 px-6 py-3 rounded-lg font-medium transition-all duration-300 transform hover:-translate-y-1 shadow-lg">
                            <i class="fas fa-search mr-2"></i>检测方法
                        </a>
                        <a href="#example" class="border-2 border-white text-white hover:bg-white hover:text-indigo-900 px-6 py-3 rounded-lg font-medium transition-all duration-300 transform hover:-translate-y-1">
                            <i class="fas fa-code mr-2"></i>代码示例
                        </a>
                    </div>
                </div>
                <div class="md:w-1/2 fade-in">
                    <div class="relative">
                        <div class="absolute -top-10 -right-10 w-64 h-64 bg-indigo-600 rounded-full mix-blend-multiply filter blur-xl opacity-50 animate-blob"></div>
                        <div class="absolute -bottom-10 -left-10 w-64 h-64 bg-purple-600 rounded-full mix-blend-multiply filter blur-xl opacity-50 animate-blob animation-delay-2000"></div>
                        <div class="relative bg-white bg-opacity-10 backdrop-filter backdrop-blur-sm rounded-2xl p-6 border border-white border-opacity-20 shadow-2xl">
                            <div class="mermaid">
                                graph LR
                                    A[线程1] -->|持有lock1| B[等待lock2]
                                    C[线程2] -->|持有lock2| D[等待lock1]
                                    B --> C
                                    D --> A
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="max-w-6xl mx-auto px-4 md:px-8 py-12 md:py-20">
        <!-- Introduction -->
        <section class="mb-20">
            <div class="text-center mb-16">
                <h2 class="header-font text-3xl md:text-4xl font-bold mb-4 text-gray-800">为什么死锁检测如此重要？</h2>
                <div class="w-24 h-1 bg-indigo-600 mx-auto mb-6"></div>
                <p class="text-lg text-gray-600 max-w-3xl mx-auto">
                    在多线程编程中，死锁是导致应用程序挂起或性能下降的常见原因。有效的死锁检测技术可以帮助开发者快速定位问题，提高系统可靠性。
                </p>
            </div>
            
            <div class="grid md:grid-cols-3 gap-8">
                <div class="bg-white rounded-xl shadow-md p-6 hover:shadow-lg transition-shadow duration-300">
                    <div class="text-indigo-600 text-3xl mb-4">
                        <i class="fas fa-bug"></i>
                    </div>
                    <h3 class="header-font text-xl font-semibold mb-3">程序挂起</h3>
                    <p class="text-gray-600">死锁会导致线程永久等待，使应用程序失去响应能力。</p>
                </div>
                <div class="bg-white rounded-xl shadow-md p-6 hover:shadow-lg transition-shadow duration-300">
                    <div class="text-indigo-600 text-3xl mb-4">
                        <i class="fas fa-tachometer-alt"></i>
                    </div>
                    <h3 class="header-font text-xl font-semibold mb-3">性能下降</h3>
                    <p class="text-gray-600">即使未完全死锁，资源争用也会显著降低系统吞吐量。</p>
                </div>
                <div class="bg-white rounded-xl shadow-md p-6 hover:shadow-lg transition-shadow duration-300">
                    <div class="text-indigo-600 text-3xl mb-4">
                        <i class="fas fa-user-shield"></i>
                    </div>
                    <h3 class="header-font text-xl font-semibold mb-3">调试困难</h3>
                    <p class="text-gray-600">死锁问题通常难以复现，需要专门的检测技术。</p>
                </div>
            </div>
        </section>

        <!-- Methods Section -->
        <section id="methods" class="mb-20">
            <h2 class="header-font text-3xl md:text-4xl font-bold mb-12 text-gray-800 text-center">死锁检测方法与工具</h2>
            
            <div class="space-y-12">
                <!-- Method 1 -->
                <div class="flex flex-col md:flex-row gap-8 items-center bg-white rounded-xl shadow-md overflow-hidden hover:shadow-lg transition-all duration-300">
                    <div class="md:w-1/3 bg-indigo-100 p-8 flex items-center justify-center">
                        <i class="fas fa-code text-indigo-600 text-6xl"></i>
                    </div>
                    <div class="md:w-2/3 p-6 md:p-8">
                        <div class="flex items-center mb-4">
                            <span class="bg-indigo-600 text-white px-3 py-1 rounded-full text-sm font-medium">方法一</span>
                        </div>
                        <h3 class="header-font text-2xl font-semibold mb-4 hover-underline-animation inline-block">代码审查</h3>
                        <ul class="space-y-3 text-gray-600">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                                <span><strong>资源获取顺序：</strong>确保多个线程在获取多个资源时遵循一致的顺序</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                                <span><strong>避免循环依赖：</strong>检查是否存在循环等待的情况</span>
                            </li>
                        </ul>
                    </div>
                </div>

                <!-- Method 2 -->
                <div class="flex flex-col md:flex-row gap-8 items-center bg-white rounded-xl shadow-md overflow-hidden hover:shadow-lg transition-all duration-300">
                    <div class="md:w-1/3 bg-purple-100 p-8 flex items-center justify-center">
                        <i class="fas fa-file-alt text-purple-600 text-6xl"></i>
                    </div>
                    <div class="md:w-2/3 p-6 md:p-8">
                        <div class="flex items-center mb-4">
                            <span class="bg-purple-600 text-white px-3 py-1 rounded-full text-sm font-medium">方法二</span>
                        </div>
                        <h3 class="header-font text-2xl font-semibold mb-4 hover-underline-animation inline-block">日志分析</h3>
                        <p class="text-gray-600 mb-4">记录线程堆栈信息以分析死锁情况。可以使用 <code class="bg-gray-100 px-2 py-1 rounded">Thread.dumpStack()</code> 方法输出线程堆栈信息。</p>
                        
                        <div class="code-block">
                            <div class="code-header text-gray-700">
                                <span>日志分析示例</span>
                                <button class="text-gray-500 hover:text-gray-700">
                                    <i class="far fa-copy"></i>
                                </button>
                            </div>
                            <pre class="text-sm"><code>public void run() {
    try {
        synchronized(resource1) {
            Thread.dumpStack();  // 输出当前线程堆栈
            synchronized(resource2) {
                // 业务逻辑
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}</code></pre>
                        </div>
                    </div>
                </div>

                <!-- Method 3 -->
                <div class="flex flex-col md:flex-row gap-8 items-center bg-white rounded-xl shadow-md overflow-hidden hover:shadow-lg transition-all duration-300">
                    <div class="md:w-1/3 bg-blue-100 p-8 flex items-center justify-center">
                        <i class="fas fa-tools text-blue-600 text-6xl"></i>
                    </div>
                    <div class="md:w-2/3 p-6 md:p-8">
                        <div class="flex items-center mb-4">
                            <span class="bg-blue-600 text-white px-3 py-1 rounded-full text-sm font-medium">方法三</span>
                        </div>
                        <h3 class="header-font text-2xl font-semibold mb-4 hover-underline-animation inline-block">使用工具检测</h3>
                        
                        <div class="grid md:grid-cols-2 gap-6">
                            <div class="bg-gray-50 p-4 rounded-lg border border-gray-200">
                                <h4 class="font-semibold text-lg mb-2 flex items-center">
                                    <i class="fas fa-desktop text-blue-500 mr-2"></i> Java VisualVM
                                </h4>
                                <ol class="text-gray-600 list-decimal list-inside space-y-1 text-sm">
                                    <li>启动 Java VisualVM</li>
                                    <li>连接到运行中的 Java 应用程序</li>
                                    <li>查看"线程"视图，检查死锁</li>
                                </ol>
                            </div>
                            <div class="bg-gray-50 p-4 rounded-lg border border-gray-200">
                                <h4 class="font-semibold text-lg mb-2 flex items-center">
                                    <i class="fas fa-terminal text-blue-500 mr-2"></i> JConsole
                                </h4>
                                <ol class="text-gray-600 list-decimal list-inside space-y-1 text-sm">
                                    <li>启动 JConsole</li>
                                    <li>连接到 Java 应用程序</li>
                                    <li>在"线程"选项卡中查看线程状态</li>
                                </ol>
                            </div>
                            <div class="bg-gray-50 p-4 rounded-lg border border-gray-200">
                                <h4 class="font-semibold text-lg mb-2 flex items-center">
                                    <i class="fas fa-memory text-blue-500 mr-2"></i> Eclipse MAT
                                </h4>
                                <ol class="text-gray-600 list-decimal list-inside space-y-1 text-sm">
                                    <li>使用 MAT 导入线程转储文件</li>
                                    <li>分析线程堆栈</li>
                                    <li>寻找死锁的迹象</li>
                                </ol>
                            </div>
                            <div class="bg-gray-50 p-4 rounded-lg border border-gray-200">
                                <h4 class="font-semibold text-lg mb-2 flex items-center">
                                    <i class="fas fa-file-code text-blue-500 mr-2"></i> jstack 命令
                                </h4>
                                <ol class="text-gray-600 list-decimal list-inside space-y-1 text-sm">
                                    <li>获取进程ID：<code class="bg-gray-100 px-1 rounded">jps</code></li>
                                    <li>生成线程转储：<code class="bg-gray-100 px-1 rounded">jstack &lt;pid&gt; &gt; thread_dump.txt</code></li>
                                    <li>分析 <code class="bg-gray-100 px-1 rounded">BLOCKED</code> 状态的线程</li>
                                </ol>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Method 4 -->
                <div class="flex flex-col md:flex-row gap-8 items-center bg-white rounded-xl shadow-md overflow-hidden hover:shadow-lg transition-all duration-300">
                    <div class="md:w-1/3 bg-green-100 p-8 flex items-center justify-center">
                        <i class="fas fa-project-diagram text-green-600 text-6xl"></i>
                    </div>
                    <div class="md:w-2/3 p-6 md:p-8">
                        <div class="flex items-center mb-4">
                            <span class="bg-green-600 text-white px-3 py-1 rounded-full text-sm font-medium">方法四</span>
                        </div>
                        <h3 class="header-font text-2xl font-semibold mb-4 hover-underline-animation inline-block">死锁检测算法</h3>
                        
                        <div class="grid md:grid-cols-2 gap-6">
                            <div class="bg-gray-50 p-4 rounded-lg border border-gray-200">
                                <h4 class="font-semibold text-lg mb-2">银行家算法</h4>
                                <p class="text-gray-600 text-sm">用于死锁预防，确保系统不会进入不安全状态。通过模拟资源分配来检测潜在死锁。</p>
                            </div>
                            <div class="bg-gray-50 p-4 rounded-lg border border-gray-200">
                                <h4 class="font-semibold text-lg mb-2">资源分配图</h4>
                                <p class="text-gray-600 text-sm">使用有向图表示资源和线程关系，检测图中是否存在循环依赖。</p>
                            </div>
                        </div>
                        
                        <div class="mt-6">
                            <div class="mermaid">
                                graph TD
                                    A[可用资源] --> B[线程1]
                                    B -->|请求| C[资源X]
                                    D[线程2] -->|持有| C
                                    D -->|请求| E[资源Y]
                                    F[线程3] -->|持有| E
                                    F -->|请求| A
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Example Section -->
        <section id="example" class="mb-20">
            <div class="text-center mb-12">
                <h2 class="header-font text-3xl md:text-4xl font-bold mb-4 text-gray-800">死锁示例与解析</h2>
                <div class="w-24 h-1 bg-indigo-600 mx-auto"></div>
            </div>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden">
                <div class="p-6 md:p-8">
                    <h3 class="header-font text-2xl font-semibold mb-6 flex items-center">
                        <i class="fas fa-code-branch text-indigo-600 mr-3"></i> Java 死锁模拟示例
                    </h3>
                    
                    <div class="code-block mb-8">
                        <div class="code-header">
                            <span>DeadlockDemo.java</span>
                            <button class="text-gray-500 hover:text-gray-700">
                                <i class="far fa-copy"></i>
                            </button>
                        </div>
                        <pre><code>public class DeadlockDemo {

    // 定义两个共享资源
    private static final Object lock1 = new Object();
    private static final Object lock2 = new Object();

    public static void main(String[] args) {
        // 创建并启动线程1
        Thread thread1 = new Thread(() -> {
            synchronized (lock1) {
                System.out.println("线程1：持有 lock1...");
                try { Thread.sleep(100); } catch (InterruptedException e) {}
                System.out.println("线程1：等待 lock2...");
                synchronized (lock2) {
                    System.out.println("线程1：成功获取 lock2！");
                }
            }
        });

        // 创建并启动线程2
        Thread thread2 = new Thread(() -> {
            synchronized (lock2) {
                System.out.println("线程2：持有 lock2...");
                try { Thread.sleep(100); } catch (InterruptedException e) {}
                System.out.println("线程2：等待 lock1...");
                synchronized (lock1) {
                    System.out.println("线程2：成功获取 lock1！");
                }
            }
        });

        thread1.start();
        thread2.start();
    }
}</code></pre>
                    </div>
                    
                    <h4 class="header-font text-xl font-semibold mb-4 flex items-center">
                        <i class="fas fa-info-circle text-indigo-600 mr-2"></i> 代码解析
                    </h4>
                    
                    <div class="grid md:grid-cols-2 gap-6 mb-8">
                        <div class="bg-indigo-50 p-4 rounded-lg">
                            <h5 class="font-semibold mb-2 text-indigo-800">资源定义</h5>
                            <p class="text-gray-700 text-sm">定义了两个共享资源 <code class="bg-indigo-100 px-1 rounded">lock1</code> 和 <code class="bg-indigo-100 px-1 rounded">lock2</code> 作为同步锁对象。</p>
                        </div>
                        <div class="bg-indigo-50 p-4 rounded-lg">
                            <h5 class="font-semibold mb-2 text-indigo-800">线程1行为</h5>
                            <p class="text-gray-700 text-sm">先持有 <code class="bg-indigo-100 px-1 rounded">lock1</code>，然后尝试获取 <code class="bg-indigo-100 px-1 rounded">lock2</code>。</p>
                        </div>
                        <div class="bg-indigo-50 p-4 rounded-lg">
                            <h5 class="font-semibold mb-2 text-indigo-800">线程2行为</h5>
                            <p class="text-gray-700 text-sm">先持有 <code class="bg-indigo-100 px-1 rounded">lock2</code>，然后尝试获取 <code class="bg-indigo-100 px-1 rounded">lock1</code>。</p>
                        </div>
                        <div class="bg-indigo-50 p-4 rounded-lg">
                            <h5 class="font-semibold mb-2 text-indigo-800">死锁形成</h5>
                            <p class="text-gray-700 text-sm">两个线程互相等待对方释放锁，导致永久阻塞。</p>
                        </div>
                    </div>
                    
                    <div class="bg-yellow-50 border-l-4 border-yellow-400 p-4 mb-8">
                        <div class="flex">
                            <div class="flex-shrink-0 text-yellow-500">
                                <i class="fas fa-exclamation-triangle"></i>
                            </div>
                            <div class="ml-3">
                                <h4 class="text-sm font-medium text-yellow-800">运行结果分析</h4>
                                <div class="mt-2 text-sm text-yellow-700">
                                    <p>程序会输出类似以下内容后挂起：</p>
                                    <pre class="bg-yellow-100 p-2 rounded mt-2 text-left">线程1：持有 lock1...
线程2：持有 lock2...
线程1：等待 lock2...
线程2：等待 lock1...</pre>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <h4 class="header-font text-xl font-semibold mb-4 flex items-center">
                        <i class="fas fa-lightbulb text-indigo-600 mr-2"></i> 解决方案建议
                    </h4>
                    
                    <div class="grid md:grid-cols-2 gap-6">
                        <div class="bg-white border border-gray-200 rounded-lg p-4 shadow-sm">
                            <h5 class="font-semibold mb-2 text-gray-800">1. 统一锁获取顺序</h5>
                            <p class="text-gray-600 text-sm">确保所有线程按相同顺序获取锁，如总是先获取 <code class="bg-gray-100 px-1 rounded">lock1</code> 再获取 <code class="bg-gray-100 px-1 rounded">lock2</code>。</p>
                        </div>
                        <div class="bg-white border border-gray-200 rounded-lg p-4 shadow-sm">
                            <h5 class="font-semibold mb-2 text-gray-800">2. 使用定时锁</h5>
                            <p class="text-gray-600 text-sm">使用 <code class="bg-gray-100 px-1 rounded">tryLock()</code> 带超时机制，避免无限等待。</p>
                        </div>
                        <div class="bg-white border border-gray-200 rounded-lg p-4 shadow-sm">
                            <h5 class="font-semibold mb-2 text-gray-800">3. 减少锁粒度</h5>
                            <p class="text-gray-600 text-sm">缩小同步代码块范围，减少锁持有时间。</p>
                        </div>
                        <div class="bg-white border border-gray-200 rounded-lg p-4 shadow-sm">
                            <h5 class="font-semibold mb-2 text-gray-800">4. 避免嵌套锁</h5>
                            <p class="text-gray-600 text-sm">尽量避免在一个同步块内获取多个锁。</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Summary Section -->
        <section class="bg-indigo-50 rounded-2xl p-8 md:p-12 mb-20">
            <div class="max-w-4xl mx-auto text-center">
                <h2 class="header-font text-3xl md:text-4xl font-bold mb-6 text-indigo-900">死锁检测最佳实践总结</h2>
                <div class="w-24 h-1 bg-indigo-600 mx-auto mb-8"></div>
                
                <div class="grid md:grid-cols-3 gap-6 mb-10">
                    <div class="bg-white p-6 rounded-lg shadow-sm">
                        <div class="text-indigo-600 text-2xl mb-3">
                            <i class="fas fa-search"></i>
                        </div>
                        <h3 class="font-semibold mb-2">预防为主</h3>
                        <p class="text-gray-600 text-sm">通过良好的设计避免死锁，优于事后检测。</p>
                    </div>
                    <div class="bg-white p-6 rounded-lg shadow-sm">
                        <div class="text-indigo-600 text-2xl mb-3">
                            <i class="fas fa-tools"></i>
                        </div>
                        <h3 class="font-semibold mb-2">工具辅助</h3>
                        <p class="text-gray-600 text-sm">熟练使用各种检测工具提高效率。</p>
                    </div>
                    <div class="bg-white p-6 rounded-lg shadow-sm">
                        <div class="text-indigo-600 text-2xl mb-3">
                            <i class="fas fa-book"></i>
                        </div>
                        <h3 class="font-semibold mb-2">持续学习</h3>
                        <p class="text-gray-600 text-sm">掌握不同的死锁处理策略和算法。</p>
                    </div>
                </div>
                
                <div class="bg-white p-6 rounded-lg shadow-sm text-left">
                    <h3 class="font-semibold mb-4 text-lg flex items-center">
                        <i class="fas fa-list-check text-indigo-600 mr-2"></i> 开发检查清单
                    </h3>
                    <ul class="space-y-3 text-gray-700">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>所有线程是否按统一顺序获取多个锁？</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>是否避免了不必要的嵌套锁？</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>是否在代码审查中检查了潜在的循环等待？</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>是否在生产环境配置了线程转储监控？</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>是否考虑了锁超时机制？</span>
                        </li>
                    </ul>
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-8">
        <div class="max-w-6xl mx-auto px-4 md:px-8">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-4 md:mb-0">
                    <h3 class="text-xl font-medium text-white">技术小馆</h3>
                    <p class="text-gray-400 text-sm mt-1">专业编程知识分享平台</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="text-indigo-400 hover:text-indigo-300 transition-colors duration-200 flex items-center">
                        <i class="fas fa-external-link-alt mr-2"></i>
                        访问技术小馆
                    </a>
                </div>
            </div>
            <div class="border-t border-gray-800 mt-6 pt-6 text-sm text-center text-gray-500">
                © 2023 技术小馆. 保留所有权利.
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
        
        // 复制代码功能
        document.querySelectorAll('.code-header button').forEach(button => {
            button.addEventListener('click', (e) => {
                const codeBlock = e.currentTarget.parentElement.nextElementSibling;
                const range = document.createRange();
                range.selectNode(codeBlock);
                window.getSelection().removeAllRanges();
                window.getSelection().addRange(range);
                document.execCommand('copy');
                window.getSelection().removeAllRanges();
                
                const originalIcon = e.currentTarget.innerHTML;
                e.currentTarget.innerHTML = '<i class="fas fa-check"></i>';
                setTimeout(() => {
                    e.currentTarget.innerHTML = originalIcon;
                }, 2000);
            });
        });
    </script>
</body>
</html>
```